﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace FindMyChamp
{
    public partial class Settings : PhoneApplicationPage
    {
        public Settings()
        {
            InitializeComponent();
            // setup form
            EnableLocationToggleSwitch.IsChecked = Settings.EnableLocation;
        }

        // property
        public static bool EnableLocation
        {
            get { return Get("EnableLocation", true); }
            set
            {
                Set("EnableLocation", value);
                GeoData.StartOrStop();
            }
        }

        // on
        private void EnableLocation_Checked(object sender, RoutedEventArgs e)
        {
            Settings.EnableLocation = true;
        }

        // off
        private void EnableLocation_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.EnableLocation = false;
        }

        // send email
        private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            new EmailComposeTask { Subject = "Privacy Question", Body = "Find My Champ", To = "jnixon@microsoft.com", }.Show();
        }

        #region helpers

        private static void Set<T>(string key, T value)
        {
            System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key] = value;
        }

        private static T Get<T>(string key, T otherwise)
        {
            try
            {
                return (T)System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key];
            }
            catch { return otherwise; }
        }

        #endregion
    }
}